package com.example.su_shi_tan_bas_lib.base;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import me.yokeyword.fragmentation.ISupportFragment;

public class DialogFragmentEx extends BaseDialogFragment {

    protected boolean mSuperBackPressedSupport = true;

    @Override
    public boolean onBackPressedSupport() {
        FragmentManager childFragmentManager = getChildFragmentManager();
        FragmentManager manager = getFragmentManager();
        int backStackEntryCount = manager.getBackStackEntryCount();
        int childBackStackEntryCount = childFragmentManager.getBackStackEntryCount();
        if (mSuperBackPressedSupport) {

            if (childBackStackEntryCount > 1) {
                popChild();
            } else if (backStackEntryCount > 1) {
                pop();
            } else {
                mSuperBackPressedSupport = false;
            }
        } else {
            Fragment parentFragment = getParentFragment();
            if (parentFragment instanceof ISupportFragment) {
                return ((ISupportFragment) parentFragment).onBackPressedSupport();
            } else {
                pop();
            }


        }
        return mSuperBackPressedSupport;
    }
}
